import { ScreenSpaceEventHandler, ScreenSpaceEventType } from 'cesium';

const Popup = {
    options: {
        temp: '',
        position: '',

    },
    viewer:null,
    selectedEntity:null,
    initialize: function (viewer, options) {
        options = _setOptions(this, options)
        if(!options.entitys || options.entitys.length <=0){
            console.log('options内的entitys是必要参数');
        }
        this.viewer = viewer
    },
    _setOptions: function (obj, options) {
        if (!obj.hasOwnProperty('options')) {
            obj.options = obj.options ? create(obj.options) : {};
        }
        for (var i in options) {
            obj.options[i] = options[i];
        }
        return obj.options;
    },
    _initClickHandler: function (viewer) {
        let handler = viewer.screenSpaceEventHandler.getInputAction(ScreenSpaceEventType.LEFT_CLICK);
        let _this = this
        viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
            // Pick a new feature
            var pickedFeature = viewer.scene.pick(movement.position);
            if (Cesium.defined(pickedFeature)) {
                if (pickedFeature.id) {
                    var entity = pickedFeature.id
                    if (_this.selectedEntity) {
                        _this.selectedEntity.billboard.image = './images/tips.png'
                    }
                    entity.billboard.image = './images/tips_s.png'
                    _this.selectedEntity = entity;
                }
            }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    }
}